package com.example.demoreqinterceptionapi.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * mvc配置类用于配置拦截器
 *
 * @author Lv
 * @date 2024/2/19
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private ApiSecureInterceptor apiSecureInterceptor;

    /**
     * 系统白名单
     */
    @Value("${system.white.list}")
    private List<String> systemWhiteList;

    /**
     * 添加拦截器并指定不拦截的路径
     *
     * @param registry 拦截器注册表
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 安全拦截除组件外的所有接口
        registry.addInterceptor(apiSecureInterceptor).excludePathPatterns(systemWhiteList);
    }
}
